package com.global.test.service.user.impl;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.global.domain.Authority;
import com.global.test.dao.user.AuthorityDAO;
import com.global.test.service.user.AuthorityService;

/**   
 *  
 * @Description:  [用一句话描述该文件做什么]   
 * @Author:       [Joly_Huang]   
 * @CreateDate:   [2014年3月18日 下午10:55:36]   
 * @UpdateUser:   [Joly_Huang]   
 * @UpdateDate:   [2014年3月18日 下午10:55:36]   
 * @UpdateRemark: [说明本次修改内容]  
 * @Version:      [v1.0] 
 *    
 */
@Service
public class AuthorityServiceImpl implements AuthorityService {
	
	private AuthorityDAO authorityDAO;
	
	public AuthorityDAO getAuthorityDAO() {
		return authorityDAO;
	}
	@Resource
	public void setAuthorityDAO(AuthorityDAO authorityDAO) {
		this.authorityDAO = authorityDAO;
	}


	@Override
	public List<Authority> getAuthorities(Integer roleId) {
		return authorityDAO.queryAuthorities(roleId);
	}
	
	@Override
	public Authority getAuthority(Integer roleId) {
		
		List<Authority> authorities = getAuthorities(roleId);
		HashMap<Authority,List<Authority>> authorityMap = new HashMap<Authority,List<Authority>>(authorities.size()/2);
		for(Authority authority : authorities){
			Authority parentAuthority = authority.getParentAuthority();
			if(null == authority.getParentAuthority()){
				authorityMap.put(parentAuthority, null);
			}else{
				if(!authorityMap.containsKey(parentAuthority)){
					authorityMap.put(parentAuthority, null);
				}
				parentAuthority.getSubAuthorities().add(authority);
			}
		}
		return null;
	}
	
	

}
